import requests

# 注意: 使用request发送web service的请求里, url就是抓包工具捕捉的URL
data = 'theIpAddress=11.12.9.9'
headers = {'Content-Type': 'application/x-www-form-urlencoded'}
r = requests.post('http://ws.webxml.com.cn/WebServices/IpAddressSearchWebService.asmx/getCountryCityByIp', data=data,
                  headers=headers)
# print(r.text)

if '美国 DoD网络信息中心' in r.text:
    print('IP查询成功.')
else:
    print('IP查询失败.')

# pip install suds-jurko 安装suds库
# WSDL: web service description language
from suds.client import Client

url = 'http://ws.webxml.com.cn/WebServices/IpAddressSearchWebService.asmx?wsdl'
client = Client(url)
resp = client.service.getCountryCityByIp('11.12.9.9')
print(resp[0][1])
